﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace QLNS.Models
{
    public class TrinhDoChuyenMonModels
    {
        public static TrinhDoChuyenMon GetChiTietTrinhDoChuyenMon(int id)
        {
            //khoi tao db
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();
            var query = (from s in context.DSTrinhDoChuyenMon
                         where s.ID == id
                         select s).FirstOrDefault();
            return query;

        }
        //danh sach dantoc
        public static List<TrinhDoChuyenMon> GetTrinhDoChuyenMonTheoCanBo(int id)
        {
            //khoi tao db
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();
            var query = from dt in context.DSTrinhDoChuyenMon
                        join ll in context.DSChuyenMon on dt.IDChuyenMon equals ll.ID
                        where dt.IDCanBo == id
                        select dt;
            return query.ToList();
        }
        public static void Add(TrinhDoChuyenMon qhgd)
        {
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();
            context.DSTrinhDoChuyenMon.AddObject(qhgd);
            context.SaveChanges();
        }
        //sua dan toc
        public static void Update(TrinhDoChuyenMon id)
        {
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();
            var query = from h in context.DSTrinhDoChuyenMon
                        where h.ID == id.ID
                        select h;
            TrinhDoChuyenMon kq = query.First<TrinhDoChuyenMon>();
            kq = id;
            context.DSTrinhDoChuyenMon.ApplyCurrentValues(kq);
            context.SaveChanges();

        }
        public static void Delete(int id)
        {
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();
            var query = (from h in context.DSTrinhDoChuyenMon
                         where h.ID == id
                         select h).FirstOrDefault();

            context.DSTrinhDoChuyenMon.DeleteObject(query);
            context.SaveChanges();

        }
        public static void DeleteAllOfPerson(int id)
        {
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();
            var query = from h in context.DSTrinhDoChuyenMon
                         where h.IDCanBo == id
                         select h;
            foreach (var item in query)
            {
                context.DSTrinhDoChuyenMon.DeleteObject(item);
                
            }
            context.SaveChanges();
        }
    }
}